<template>
  <BouncedPanel @close="close" :style="{ width: dialogWidth, height: dialogHeight }" v-show="showMark">
    <template v-slot:title><slot name="title"></slot></template>
    <slot name="main"></slot>
  </BouncedPanel>
</template>

<script>
/**
 * 地图弹出框
 *
 * @author 阳坤
 * @since  2022/11/15
 * */

import BouncedPanel from '../../../components/detail-panel'
export default {
  name: 'TrafficMapPopup',
  components: {
    BouncedPanel
  },
  data() {
    return {
      dialogHeight: '2.5rem',
      dialogWidth: '4rem',
      theme: 'dialog-blue', // 主题
      showMark: false // 显示标签
    }
  },

  methods: {
    /**
     * 显示地图弹出框
     * */
    showPopup(width, height, theme, lngLat, offsetLngLat = null) {
      try {
        this.dialogWidth = width / 100 + 'rem' || '4rem'
        this.dialogHeight = height / 100 + 'rem' || '2.5rem'
        this.theme = theme
        const infoWindow = new AMap.InfoWindow({
          isCustom: true, // 使用自定义窗体
          content: this.$el,
          offset: new AMap.Pixel(0, -30)
        })
        this.showMark = true
        infoWindow.open(this.$mapSdk().map, lngLat)

        this.$mapSdk().setMvMapCenterAndZoom(offsetLngLat || lngLat, 13)
      } catch (e) {
        console.log(e)
      }
    },

    close() {
      this.$mapSdk().setMvMapClickMarker()
      this.hidePopup()
    },
    hidePopup() {
      this.showMark = false
      this.$mapSdk().map.clearInfoWindow()
    },
    mounted() {
      this.$nextTick(() => {
        // 禁用右键
        document.oncontextmenu = new Function('event.returnValue=false')
        // 禁用选择
        document.onselectstart = new Function('event.returnValue=false')
      })
    }
  }
}
</script>

<style scoped lang="less">
/deep/.mz-panel-content {
  .title {
    font-size: 20px !important;
    font-family: 'pangmenzhengdaoregular';
    font-weight: 400 !important;
    color: #266bf4 !important;
    line-height: 30px !important;
  }
}
</style>
